import { request } from '@/utils/request'
import type {
  KnowledgeParams,
  KnowledgePage,
  PageParams,
  DoctorPage,
  FollowType,
  TopDep,
  Image,
  ConsultOrderPreParams,
  ConsultOrderPreData,
  PartialConsult,
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage
} from './../types/consult.d'

// 拿数据接口
export const reqGetKnowledgePage = (params: KnowledgeParams) => {
  return request<KnowledgePage>('patient/home/knowledge', 'get', params)
}

// 拿医生列表接口
export const reqGetDoctorList = (params: PageParams) => {
  return request<DoctorPage>('home/page/doc', 'GET', params)
}

// 关注-取消关注 操作
export const reqFollowDoctor = (type: FollowType, id: string) => {
  return request('like', 'POST', { type, id })
}

// 获取所有科室 一级的科室 是个数组
export const reqGetDepAll = () => request<TopDep[]>('dep/all')

// 上传图片接口函数
export const reqUploadImg = (file: File) => {
  const fd = new FormData()
  fd.append('file', file)
  return request<Image>('upload', 'post', fd)
}

/**
 * 极速问诊之支付页面，数据渲染接口
 * @param params {type: xxx, ilness: xxx}
 */
export const reqGetConsultOrderPre = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('patient/consult/order/pre', 'GET', params)

/**
 * 极速问诊之支付页面-生成订单接口
 * @param data { store.consult }
 */
export const reqCreateConsultOrder = (data: PartialConsult) =>
  request<{ id: string }>('/patient/consult/order', 'POST', data)

/**
 *
 * @param data 订单支付接口 支付方式，订单id，和会跳页面地址
 */
export const reqGetConsultOrderPayUrl = (data: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => request<{ payUrl: string }>('patient/consult/pay', 'post', data)

/**
 * 获取订单详情 订单状态
 * @param orderId { order: string }
 */
export const reqGetConsultOrderDetail = (orderId: string) =>
  request<ConsultOrderItem>('patient/consult/order/detail', 'GET', { orderId })

/**
 * 查看原始处方
 * @param id msg.prescription?.id
 */
export const reqGetPrescriptionPic = (id: string) =>
  request<{ url: string }>(`/patient/consult/prescription/${id}`)

/**
 *  评价问诊
 */
export const reqEvaluateConsultOrder = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) => request<{ id: string }>('/patient/order/evaluate', 'POST', data)

//  = = = = = = = = = = = = =  问诊记录模块   = = = = = = = = = = = = = =
/**
 * @param params
 */
export const reqGetConsultOrderList = (params: ConsultOrderListParams) =>
  request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)

/**
 * 取消订单
 */
export const reqCancelOrder = (id: string) => request(`/patient/order/cancel/${id}`, 'PUT')

/**
 * 删除订单
 */
export const reqDeleteOrder = (id: string) => request(`/patient/order/${id}`, 'DELETE')
